package com.tjvib.adapter;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.tjvib.R;
import com.tjvib.bean.DataSetInfo;
import com.tjvib.util.LogUtil;
import com.tjvib.util.PressUtil;
import com.tjvib.view.fragment.DatasetFragment;

import java.util.ArrayList;
import java.util.List;

public class DatasetAdapter extends BaseQuickAdapter<DataSetInfo, BaseViewHolder> {
    private Context context;
    private DatasetFragment datasetFragment;

    public DatasetAdapter(int layoutResId, @Nullable List<DataSetInfo> data, Context context, DatasetFragment datasetFragment) {
        super(layoutResId, data);
        this.context = context;
        this.datasetFragment = datasetFragment;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, DataSetInfo datasetBean) {
        baseViewHolder.setText(R.id.item_dataset_tv_name, datasetBean.getName())
                .setText(R.id.item_dataset_tv_con,
                        datasetBean.getType().equals("local") ? "local" : "sensor" + "\n" + datasetBean.getTimestamp());

        if (datasetBean.isAnalyzable()) {
            baseViewHolder.setImageResource(R.id.item_dataset_iv_status, R.mipmap.lock_off);
        } else {
            baseViewHolder.setImageResource(R.id.item_dataset_iv_status, R.mipmap.lock_on);
        }

        baseViewHolder.findView(R.id.item_dataset_ll_del).setOnClickListener(v ->
                datasetFragment.showDeleteDataSetDialog(datasetBean)
        );

        baseViewHolder.findView(R.id.item_dataset_rl).setOnClickListener(v ->
                datasetFragment.bottomDatasetDialog.showBottomDialog(context, datasetBean)
        );

        PressUtil.setPressChange(context, baseViewHolder.findView(R.id.item_dataset_ll_del),
                baseViewHolder.findView(R.id.item_dataset_rl));
    }
}
